package demo;


import java.util.concurrent.*;

public class FutureExample {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ExecutorService executorService = Executors.newFixedThreadPool(2);
        Callable<Integer> task = ()->{
            Thread.sleep(1000);
            return 42;
        };
        Future<Integer> future = executorService.submit(task);

        System.out.println("Doing something else...");
        Integer result = future.get();
        System.out.println("result : "+result);
        executorService.shutdown();

    }
}
